package com.modules.controller.sys;



import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.controller.MyController;
import com.common.vo.LoginUser;
import com.common.vo.Result;
import com.modules.entity.sys.MenuEntity;
import com.modules.service.sys.MenuService;


/**
 * menus控制层
 * @author yyq
 *
 */
@Controller
@RequestMapping("/sys/menu")
public class MenusController extends MyController<MenuEntity>{
	
	@Autowired
	private MenuService menuService;
	
	
	/**
	 * 查询
	 * @return
	 */
	@GetMapping("/select")
	@ResponseBody
	public Result<?> select(MenuEntity menu){
		return menuService.select(getPage(), menu);
	}
	
	/**
	 * 查询树形表格
	 * @return
	 */
	@GetMapping("/selectTreeTable")
	@ResponseBody
	public Result<?> selecTreeTable(MenuEntity menu){
		return menuService.selecTreeTable(menu);
	}
	
	/**
	 * 保存
	 * @return
	 */
	@RequestMapping("/save")
	@ResponseBody
	public Result<?> save(MenuEntity menu){
		return menuService.saveMenu(menu);
	}
	
	/**
	 * 删除
	 * @return
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Result<?> delete(MenuEntity menu){
		return menuService.delete(menu.getMid());
	}
	
	/**
	 * 更改状态
	 * @return
	 */
	@RequestMapping("/updateState")
	@ResponseBody
	public Result<?> updateState(MenuEntity menu){
		return menuService.updateState(menu);
	}
	
	/**
	 * 获取左侧菜单
	 * @return
	 */
	@RequestMapping("/selectTree")
	@ResponseBody
	public Result<?> selectTree(){
		LoginUser user = getUser();
		return menuService.selectTree(user.getRid());
	} 
	
	/**
	 * 获取左侧菜单所有
	 * @return
	 */
	@RequestMapping("/selectTreeAll")
	@ResponseBody
	public List<Map<String, Object>> selectTreeAll(){
		return menuService.selectTreeAll();
	} 
	
	/**
	 * 菜单选择角色
	 * @return
	 */
	@RequestMapping("/selectMenuRole")
	@ResponseBody
	public Result<?> selectMenuRole(Integer mid){
		return menuService.selectMenuRole(mid);
	} 
	
	/**
	 * 保存菜单选择角色
	 * @return
	 */
	@RequestMapping("/saveMenuRole")
	@ResponseBody
	public Result<?> saveMenuRole(Integer[] rids, Integer mid){
		return menuService.saveMenuRole(rids, mid);
	} 
	
}